package com.gsnd.gsnd21study.web;


import com.gsnd.gsnd21study.entity.Student;
import com.gsnd.gsnd21study.utils.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {
    // 请求映射：将一段网址和一个方法进行绑定
    @RequestMapping("/hello")
    public void hello(){
        System.out.println("hello");
    }

    // 研究一下返回值
    // 最像基本类型的引用类型：字符串
    @RequestMapping("/test1")
    public Result<String> test1(){
        return Result.success("hello");
    }
    // 单个对象（以Student为例）
    @RequestMapping("/test2")
    public Result<Student> test2(){
        Student student = new Student();
        student.setSno(1L);
        student.setName("张三");
        student.setAge(20);
        student.setGender("男");
        return Result.success(student);
    }
    // 多个对象 =》集合
    @RequestMapping("/test3")
    public Result<List<Student>> test3(){
        Student student1 = new Student();
        student1.setSno(1L);
        student1.setName("张三");
        student1.setAge(20);
        student1.setGender("男");
        Student student2 = new Student();
        student2.setSno(2L);
        student2.setName("李四");
        student2.setAge(19);
        student2.setGender("男");
        Student student3 = new Student();
        student3.setSno(3L);
        student3.setName("王武");
        student3.setAge(18);
        student3.setGender("男");
        List<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        list.add(student3);
        return Result.success(list);
    }
}
